<template>
  <div class="content" v-loading="loading">
    <!--头部-->
    <div class="header-setting">
      <a-breadcrumb class="breadcrumb">
        <a-breadcrumb-item>
          <a href="../main">首页</a>
        </a-breadcrumb-item>
        <a-breadcrumb-item>运营服务</a-breadcrumb-item>
        <a-breadcrumb-item>巡查反馈</a-breadcrumb-item>
      </a-breadcrumb>
      <!--查询条件-->
      <div class="box-condition-body">
        <div class="box-condition-item">
          <div class="box-item">
            <div style="margin: 0 50px">时间</div>
            <template>
              <div class="button_time">
                <a-button
                  type="primary"
                  @click="button_time(0)"
                  :style="computedStyle(0)"
                  >今天</a-button
                >
                <a-button
                  type="primary"
                  @click="button_time(1)"
                  :style="computedStyle(1)"
                  >昨天</a-button
                >
                <a-button
                  type="primary"
                  @click="button_time(2)"
                  :style="computedStyle(2)"
                  >本周</a-button
                >
                <a-button
                  type="primary"
                  @click="button_time(3)"
                  :style="computedStyle(3)"
                  >上周</a-button
                >
                <a-button
                  type="primary"
                  @click="button_time(4)"
                  :style="computedStyle(4)"
                  >本月</a-button
                >
              </div>
            </template>
            <template>
              <div style="margin: auto 50px">
                <a-range-picker
                  :showTime="{ format: 'HH:mm' }"
                  format="YYYY-MM-DD HH:mm"
                  :placeholder="['开始时间', '结束时间']"
                  @ok="onOk"
                  @change="onChange"
                  :value="rangePicker()"
                />
              </div>
            </template>
          </div>
        </div>
        <div class="box-condition-item">
          <div style="margin: 0 50px">停车点</div>
          <template>
            <a-input
              style="margin: 0 100px 0 0px; width: 200px"
              v-model="inputPark"
              placeholder="停车点"
            />
          </template>
          <div style="margin: 0 50px">巡查人员</div>
          <template>
            <a-input
              style="margin: 0 100px 0 0px; width: 200px"
              v-model="inputWorker"
              placeholder="巡查人员名称"
            />
          </template>

          <div class="select-box" style="margin-left: 20px">
            <a-button icon="search" type="primary" @click="selecDuate"> 查询 </a-button>
            &nbsp;
            <a-button icon="sync" @click="reset"> 重置 </a-button>
          </div>
        </div>
      </div>
    </div>

    <div class="box-form">
      <!--工具栏-->
      <div class="box-tool"></div>
      <!--数据表格-->
      <div class="box-table">
        <a-table
          :columns="columns"
          :dataSource="dataSource"
          :pagination="pagination"
          bordered
          size="small"
          :scroll="scroll"
          :customRow="customRow"
          @change="queryPageData"
          rowKey="id"
          :rowClassName="setRowClassName"
        >
          <!-- <template slot="deviceEnergy" slot-scope="text">
                        <div>{{text}}%</div>
                    </template>
                    <template slot="log" slot-scope="text, record">
                        <a-button type="primary" @click="log_trigger(record.imei)">设备日志</a-button>
                    </template>
                    <template slot="heartbeat" slot-scope="text, record">
                        <a-button type="primary" @click="heartbeat_trigger(record.imei)">心跳历史</a-button>
                    </template> -->
        </a-table>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import PatrolFeedbackApi from "../../api/operate/PatrolFeedback";

const columns = [
  {
    title: "序号",
    dataIndex: "index",
    width: "5%",
  },
  {
    title: "统计日期",
    dataIndex: "createdTime",
    width: "10%",
  },
  {
    title: "巡查员",
    dataIndex: "nickName",
    width: "10%",
  },
  {
    title: "停车点",
    dataIndex: "parkName",
    width: "10%",
  },
  {
    title: "地址",
    dataIndex: "address",
    width: "10%",
  },
  {
    title: "内容",
    dataIndex: "content",
    width: "10%",
  },
  {
    title: "处理状态",
    dataIndex: "status",
    width: "10%",
  },
  {
    title: "回复内容",
    dataIndex: "contentReply",
    width: "10%",
  },
];
const dataSource = [];

const condition = {
  limit: 10,
  curr: 1,
  parkId: "",
  parkName: "",
  workerName: "",
  timeScreenCondition: 6,
  startTimeStamp: "",
  endTimeStamp: "",
};

export default {
  name: "PatrolFeedback",
  /*数据层*/
  data() {
    return {
      parks: [],
      selectId: -1,
      momentArr: [],
      columns: columns,
      dataSource: dataSource,
      /*分页插件*/
      pagination: {
        showTotal: (total) => `共${total}条`,
        total: 0,
        defaultCurrent: 1,
        showQuickJumper: true,
        defaultPageSize: 10,
      },
      /*表格固定头部*/
      scroll: {
        y: 550,
      },
      tableState: {
        rowId: -1,
      },
      /*当前选中的行数据*/
      currRowData: "",
      condition,
      inputPark: "",
      inputWorker: "",
      loading: false,
    };
  },
  /*方法层*/
  methods: {
    /*时间按钮控制*/
    button_time(e) {
      this.selectId = e;
      let momentStart;
      let momentEnd;
      switch (e) {
        case 0:
          momentStart = moment().startOf("day");
          momentEnd = moment().endOf("day");
          break;
        case 1:
          momentStart = moment().add("day", -1).startOf("day");
          momentEnd = moment().add("day", -1).endOf("day");
          break;
        case 2:
          momentStart = moment().week(moment().week()).startOf("week");
          momentEnd = moment().week(moment().week()).endOf("week");
          break;

        case 3:
          momentStart = moment()
            .week(moment().week() - 1)
            .startOf("week");
          momentEnd = moment()
            .week(moment().week() - 1)
            .endOf("week");
          break;
        case 4:
          momentStart = moment().month(moment().month()).startOf("month");
          momentEnd = moment().month(moment().month()).endOf("month");
          break;
        default:
          break;
      }
      this.momentArr[0] = momentStart;
      this.momentArr[1] = momentEnd;
      this.queryData();
    },
    /*日期选择*/
    onChange(date) {
      this.selectId = -1;
      this.momentArr = date;
    },
    onOk() {
      this.selectId = -1;
      this.queryData();
    },
    rangePicker() {
      return this.momentArr;
    },

    /*获取数据*/
    queryPageData(page) {
      this.queryData(page.current);
    },

    queryData(pageNum) {
      this.loading = true;
      let condition = this.condition;
      let beginMoment = this.momentArr[0];
      let endMoment = this.momentArr[1];
      if (beginMoment != undefined && endMoment != undefined) {
        condition.startTimeStamp = new Date(beginMoment).getTime() / 1000;
        condition.endTimeStamp = new Date(endMoment).getTime() / 1000;
        condition.timeScreenCondition = 6;
      } else {
        condition.timeScreenCondition = 0;
      }
      condition.curr = pageNum || 1;

      condition.workerName = this.inputWorker;
      condition.parkName = this.inputPark;
      PatrolFeedbackApi.getFeedbackList(condition)
        .then((data) => {
          let { list, total, pageNum, pageSize } = data.data;
          //处理序列号
          for (var a in list) {
            list[a].index = parseInt(a) + 1 + (pageNum - 1) * pageSize;
          }
          let array = list || [];
          array = array.map((item, index) => {
            // array.put("index",index);
            return { ...item, id: total - (pageNum - 1) * pageSize - index };
          });
          this.dataSource = array;
          this.pagination.total = total;
          this.loading = false;
        })
        .catch((error) => {
          console.log("获取巡查反馈数据异常", error);
          this.$message.error("获取巡查反馈数据异常");
          this.loading = false;
        });
    },

    /*表格*/
    customRow(record) {
      return {
        on: {
          // 事件
          click: () => {
            this.currRowData = record;
            this.tableState.rowId = record.id;
          }, // 点击行
        },
      };
    },
    setRowClassName(record) {
      return record.id === this.tableState.rowId ? "clickRowStyl" : "";
    },
    selecDuate() {
      this.queryData();
    },
    reset() {
      Object.assign(this.$data, this.$options.data()); // 初始化data
      this.queryData();
    },
  },
  /*计算层*/
  computed: {
    computedStyle() {
      return function (selectId) {
        return this.selectId == selectId ? "" : "";
      };
    },
  },
  /*渲染层*/
  mounted() {
    this.queryData();
  },
};
</script>

<style>
.content {
  width: 100%;
  height: 100%;
}

.header-setting {
  width: 100%;
  height: 174px;
  background: #fff;
}

.header-setting .breadcrumb {
  margin-left: 41px;
  padding-top: 15px;
}

/*表格行选中背景颜色*/
.clickRowStyl {
  background-color: #c1e0fd;
}

.box-condition-item {
  display: flex;
  align-items: center;
  min-width: 1500px;
  margin-top: 10px;
  margin-bottom: 10px;
  padding: 5px 0;
}

.box-condition-item .box-item {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 5px 5px 20px 5px;
}

.button_time button {
  margin-left: 10px;
}

/* 表单 */
.box-form {
  padding-left: 40px;
  padding-right: 40px;
  min-height: 705px;
  background: #fff;
  margin-top: 8px;
}

.box-form .box-tool {
  padding-top: 11px;
  margin: 8px 0;
  width: 100%;
  /* flex */
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>
